package com.appcenter.application.mapper;

import com.appcenter.application.input.Permission.GetPermissionsInput;
import com.appcenter.application.model.Dics;
import com.appcenter.application.model.Permissions;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;

@org.apache.ibatis.annotations.Mapper
@Repository
public interface PermissionsMapper extends Mapper<Permissions> {

    //查询权限名称是否存在
    @Select("select * from permissions where AppId=#{AppId} AND PermissionName=#{PermissionName} ")
    public List<Dics> getNameCount(@Param("AppId") String AppId,@Param("PermissionName") String PermissionName);

    //查询权限名称是否存在
    @Select("select * from permissions where AppId=#{AppId} AND PermissionName=#{PermissionName} and Id <> #{Id}")
    public List<Dics> getNameCountNoId(@Param("AppId") String AppId,@Param("PermissionName") String PermissionName,@Param("Id") String Id);

    //查询当前应用下最大排序值
    @Select("select * FROM permissions WHERE AppId=#{AppId} ORDER BY ListOrder DESC limit 0,1")
    public Permissions maxListOrder(String AppId);

    //搜索查询信息
    @Select("<script>" +
            "select * FROM permissions where 1=1" +
            "" +
            " <when test='keyword!=null'>" +
            " AND (PermissionName like concat('%',#{keyword},'%'))" +
            " </when>" +
            "" +
            " <when test='AppId!=null'>" +
            " AND AppId=#{AppId}" +
            " </when>" +
            "</script>")
    public List<Permissions> searchPermissionList(GetPermissionsInput input);





}
